home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 2 / Gekikoh Dennoh Club Vol. 2 (Japan).7z / Gekikoh Dennoh Club Vol. 2 (Japan) (Track 01).bin / games / mashou / plugin / topal.c < prev    next >
Text File  |  1997-06-02  |  2KB  |  105 lines

  1. /*
  2.                                 
  3.             パレット色変更
  4.         toPAL.x filename.PAL
  5.         filename.PAL    パレットファイル 非圧縮.PALのみ対応
  6.         return        0:no error
  7.                 1:no memory error
  8.                 2:command error
  9.                 3:file open error etc.
  10.     徐々に、パレットが、指定した、PALファイルの色になる。
  11.                                 
  12.                         by SJOM
  13. */
  14.  
  15.  
  16. #include <sys/iocs.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19.  
  20. static char *pallist;    /*[0]blue [1]red [2]green [3]I */
  21.  
  22.  
  23. static void
  24. pal_tocol(char *pallist)
  25. {
  26.     int block,code,col=0,bl=0,rd=0,gr=0;
  27.     for (block=1;block<16;block++) {
  28.     _iocs_spalet(0,block,-1);        /* dummy */
  29.         for (code=0;code<16;code++) {
  30.             gr=_iocs_spalet(code+0x80000000,block,-1);
  31.             bl=(gr>>=1) & 31;
  32.             rd=(gr>>=5) & 31;
  33.             gr>>=5;
  34.             if (bl!=pallist[0]) {
  35.                 if (bl>pallist[0]) {
  36.                     bl--;
  37.                 } else {
  38.                     bl++;
  39.                 };
  40.             };
  41.             if (rd!=pallist[1]) {
  42.                 if (rd>pallist[1]) {
  43.                     rd--;
  44.                 } else {
  45.                     rd++;
  46.                 };
  47.             };
  48.             if (gr!=pallist[2]) {
  49.                 if (gr>pallist[2]) {
  50.                     gr--;
  51.                 } else {
  52.                     gr++;
  53.                 };
  54.             };
  55.             col=(gr<<11) | (rd<<6) | (bl<<1) | pallist[3];
  56.             _iocs_spalet(code+0x80000000,block,col);
  57.             pallist+=4;
  58.         };
  59.     };
  60. }
  61.  
  62. static void
  63. pal_set(FILE *file,char *list)
  64. {
  65.     int i=0,color=0,b=0;
  66.     for (i=0;i<240;i++) {
  67.         if ((b=fgetc(file))==EOF)
  68.             exit(3);
  69.         color=b*256;    /* b<<8 */
  70.         if ((b=fgetc(file))==EOF)
  71.             exit(3);
  72.         color+=b;
  73.         list[3]=color & 1;        /* I     */
  74.         *list++=(color>>=1) & 31;    /* blue  */
  75.         *list++=(color>>=5) & 31;    /* red   */
  76.         *list++=(color>>=5);        /* green */
  77.         list++;
  78.     };
  79. }
  80.  
  81.  
  82. int
  83. main(int argc,char **argv)
  84. {
  85.     int j=0;
  86.     FILE *pat_file=malloc(sizeof(FILE *));
  87.     if (pat_file==NULL)
  88.         exit(1);
  89.     if ((pallist=malloc(240*4))==NULL)
  90.         exit(1);
  91.     if (argc!=2)
  92.         exit(2);
  93.     argv++;
  94.     if ((pat_file=fopen(*argv,"rb"))==NULL)
  95.         exit(3);
  96.     pal_set(pat_file,pallist);
  97.     for (j=0;j<32;j++) {
  98.         pal_tocol(pallist);
  99.     };
  100.     /* fclose(pat_file); */
  101.     exit(0);
  102. }
  103.  
  104.  
  105.